<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<title>项目汇</title>
<link href="/res/css/respective/xiangMuHui/xiangMuHui.css" rel="stylesheet">
	<style type="text/css">
		.sxx b[data-name] {
            max-width: 50px;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
		}
	</style>
</head>
<body>
[#assign link="xmh" /]
[#include "/front/common/front_head.html"]
	<div class="fixFaBu">
		<img src="/res/images/respective/xiangMuHui/a_03.png"/>
		<img class="faBu" src="/res/images/respective/xiangMuHui/a_06.png" onclick="window.location.href='/enquiry/all/choose'"/>
	</div>
	<div class="warp" style="margin-top: 30px;"> 
		<div class="xiangMuHuiOuter">
			 <div style="background: #222e3c;padding: 35px 0 25px 0;">
			 	<div class="spCent itermOne">
			 		<div class="addIterm" id="searchItem">
			 			 <strong>项目汇 </strong>
			 			 <label style="margin-right: 30px;width: auto;" id="total"></label>
			 			 <div class="sxx">

			 			 </div>
			 		</div>
			 		<hr/>
			 		<div class="duoOuter danXuan" style="position: relative;">
			 			<label>产品分类：</label> 
			 			<div class="keXuan" data-name="categorySId">
							[#list categoryList as category]
								<dfn data-value="${category.id!}">${category.name!}</dfn>
							[/#list]
			 			</div>
			 			<div class="itermChose">
			 				<a class="zhanKaiLink" onclick="more(this)">更多<i class="zhanKai"></i></a>
			 				<b class="duoChose" onclick="multi(this)">多选+</b>
			 			</div>
			 		</div>
			 		<div class="duoOuter danXuan">
			 			<label>需求类型：</label> 
			 			<div class="keXuan" data-name="qtype">
			 				<dfn data-value="1">预算询价</dfn>
			 				<dfn data-value="2">采购询价</dfn>
			 			</div>  
			 		</div>
			 		<div class="duoOuter danXuan">
			 			<label>有无报价：</label> 
			 			<div class="keXuan" data-name="hasQuote">
			 				<dfn data-value="1">有报价/报名</dfn>
			 				<dfn data-value="0">无报价/报名</dfn>
			 			</div>  
			 		</div>
			 		<div class="duoOuter danXuan" style="position: relative;">
			 			<label>地区：</label> 
			 			<div class="keXuan" data-name="area">
							[#list areaList as area]
			 					<dfn data-value="${area.code!}">${area.name!}</dfn>
							[/#list]
			 			</div>
			 			<div class="itermChose">
			 				<a class="zhanKaiLink" onclick="more(this)">更多<i class="zhanKai"></i></a>
			 				<b class="duoChose" onclick="multi(this)">多选+</b>
			 			</div>
			 		</div>
			 		<div style="margin-bottom: 0;">
			 			<label>发布时间：</label> 
			 			<div style="display: inline-block;">
			 				<input style="margin-right: 5px;" placeholder="开始时间" id="startPubDate"/> -
			 				<input style="margin:0 10px 0 5px;" placeholder="结束时间" id="endPubDate"/>
			 				<a class="confirmLink" href="javascript:pageNo = 1; search()">确认</a>
			 			</div>
			 			<div style="display: inline-block;float: right;">
			 				<label style="width: auto;">截止时间：</label> 
			 				<input style="margin-right: 5px;" placeholder="开始时间" id="startDeadline"/> -
			 				<input style="margin:0 10px 0 5px;" placeholder="结束时间" id="endDeadline"/>
			 				<a class="confirmLink" href="javascript:pageNo = 1; search()">确认</a>
			 			</div>
			 		</div>
			 	</div>
			 </div>
			 <div style="background-color: #f2f2f2;"> 
			 <div class="spCent itermTwo">
			 	<table style="width: 100%;">
			 		<caption style="overflow: hidden;border-bottom: 1px solid #dedede;">
			 			<div style="display: inline-block;float: left;">
			 				<b class="acTab" onclick="switchTab(this)">综合排序</b>
				 			<b onclick="switchTab(this, 'id')" data-sort="">发布时间<i class="time"></i></b>
				 			<b onclick="switchTab(this, 'deadline')" data-sort="">截止时间<i class="time"></i></b>
				 			<em><i id="hasAttach"></i><span>有图/附件</span></em>
			 			</div>
			 			<div class="fanYe">
			 				 <em style="color: #fca711;" id="pageNo">1</em>
			 				 <em style="margin-left: 0px;" id="pages" data-pages="">/&nbsp;1</em>
			 				 <a href="javascript:if(pageNo > 1) {pageNo--; search();}">&lt;</a>
			 				 <a style="margin-left: -5px;" href="javascript:if(pageNo < Number($('#pages').attr('data-pages'))) { pageNo++;search();}">&gt;</a>
			 			</div>
			 		</caption>
			 		<tbody id="dataTbody">
			 		</tbody>
			 	</table>

				 <div id="page"/>

			 </div>
			 </div> 
			<!-- 底部菜单-->
			[#include "/front/common/front_foot.html"]
		</div> 
	</div>

	<!-- 数据展示模板 -->
	<script type="text/html" id="dataTemplate">
		{{# $.each(d.data, function(n, list) { }}
        <tr>
			{{# $.each(list, function(i, v) { }}
            <td {{# if(v.state == 4 || v.state == 5) { }}class="ptdPad"{{# } }}>
                <div>
                    <p class="comBack" style="cursor: pointer; background: url('/res/images/xmh/xmh_{{ (n + 1) * (i + 1) }}.jpg') center no-repeat" onclick="window.open('/xmh/{{v.id}}')">
                        <strong>{{ v.enquiryName }}</strong>
                        <small>
							{{ qtype_array[v.qtype] }}
						</small>
                    </p>
                    <div class="comIntro">
                        <div>
                            <img src="{{v.ppLogo || v.pLogo || v.logo ||'/res/images/common/userLogo_05.png'}}" alt="" width="25px" height="25px"/>
                            <em>{{v.ppCompanyName || v.pCompanyName || v.companyName}}</em>
                        </div>
                        <div {{# if(v.state == 4 || v.state == 5) { }}class="endArd"{{# } }}>
                            {{# if(v.state == 4) { }}<img style="width:auto;" src="/res/images/respective/xiangMuHui/closed_03.png" alt="logo"/>{{# } }}
                            {{# if(v.state == 5) { }}<img style="width:auto;" src="/res/images/respective/xiangMuHui/end_03.png" alt="logo"/>{{# } }}
                            <h4><dfn>发布时间：</dfn>{{v.pubdate}}</h4>
                            <h4><dfn>截止时间：</dfn>{{ moment(v.deadline).format('YYYY-MM-DD') }}</h4>
                            {{# if(v.state != 4 && v.state != 5) { }}
							{{# var d = fromNow(moment(v.deadline).add(1, 'days')); }}
                            <h5>
                                <i></i>
                                <dfn style="margin-left: -5px;">剩余</dfn>
								{{# if(d.day > 0) { }}
                                <strong>{{ d.day }}</strong>
                                <big>天</big>
								{{# } }}
								{{# if(d.hour > 0) { }}
                                <strong>{{ d.hour }}</strong>
                                <big>小时</big>
								{{# } }}
								{{# if(d.minute > 0) { }}
                                <strong>{{ d.minute }}</strong>
                                <big>分钟</big>
								{{# } }}
                            </h5>
                            <h4>
                                <dfn>进度情况：</dfn><span>{{ enquiry_state[v.state] }}</span>
                                <dfn style="margin-left: 20px;">已有报价：</dfn><strong>{{v.quoteNum}}家</strong>
                            </h4>
                            {{# } else { }}
							<h4>
                                <dfn>已有报价：</dfn><strong>{{v.quoteNum}}家</strong>
							</h4>
							{{# } }}
                            <div style="text-align: center;">
                                <button class="blue" {{# if(v.state == 4 || v.state == 5) { }}style="background-color:#d4d4d4;color:white;border-color:#d4d4d4;cursor:default;" disabled="disabled"{{# } }} type="button" onclick="toQuote('{{v.id}}')">参与报价</button>
                                <button class="white" style="margin-right: 0;" type="button"
										{{# if(v.state == 0 || v.state == 3) { }}onclick="layer.alert('该询价单正在审核中,请于一个工作日后点击查阅！')"{{# } else { }} onclick="window.open('/xmh/{{v.id}}')" {{# } }} >查看详情</button>
                            </div>
                        </div>
                    </div>
                </div>
            </td>
			{{# if(i != list.length - 1) { }}
			<!-- 最后一个不加td -->
			<td class="navTd"></td>
			{{# } }}
			{{# }) }}

            {{# if(list.length < showSize) { }}
            <!-- 当一行数量小于showSize的时候 -->
            <td class="navTd"></td>
			{{# for(var j = list.length; j < showSize; j++) { }}
            <td class="ptdPad"></td>
			{{# if(j != showSize - 1) { }}
            <td class="navTd"></td>
			{{# } }}
			{{# } }}
            {{# } }}
        </tr>
		{{# }) }}
	</script>

	<!-- 搜索项目 -->
    <script type="text/html" id="searchItemTemplate">
        <div><b data-name="{{d.name}}" data-value="{{d.value}}">{{d.text}}<i onclick='removeItem(this)'></i></b></div>
	</script>

	<script type="text/javascript" src="/res/third/layer/layer.js"></script>  
    <script type="text/javascript" src="/res/third/laytpl/laytpl.js"></script>
    <script type="text/javascript" src="/res/third/laypage/laypage.js"></script>
    <script type="text/javascript" src="/res/third/laydate/laydate.js"></script>
    <script type="text/javascript" src="/res/js/common/moment.min.js"></script>
    <script type="text/javascript" src="/res/js/common/util.js"></script>
	<script type="text/javascript">
	
		var pageNo = 1;		//当前页码
		var showSize = 4;	//每行显示数量
		var rowSize = 4;	//每页显示行数
		var qtype_array = { 1 : '预算询价', 2 : '采购询价' }
		var enquiry_state = { 0 : '审核中', 1 : '进行中', 2 : '已截止', 3 : '审核中', 4 : '已关闭', 5 : '已截止' };

        laypage.dir = '/res/third/laypage/skin/aztpage.css';
		$(function() {
			search();
            initDate('startPubDate', 'endPubDate');
            initDate('startDeadline', 'endDeadline');

			//绑定单选点击事件
            $('.xiangMuHuiOuter .itermOne').on('click', '.danXuan dfn', function() {
				var name = $(this).parent().attr('data-name');
				var value = $(this).attr('data-value');
                $(this).parents(".danXuan").hide();

                addSearchItem(name, value, $(this).text().trim());
                pageNo = 1;
                search();
			});
			
            $(".fixFaBu .faBu").hover(function(){
        		$(this).attr("src","/res/images/respective/xiangMuHui/c_06.png");
        	},function(){
        		$(this).attr("src","/res/images/respective/xiangMuHui/a_06.png");
        	});

			//绑定多选点击事件
            $(".xiangMuHuiOuter .itermOne").on("click", ".duoXuan dfn",function(){
                $(this).find("b").remove();
                $(this).addClass("chosedfn");
                var x='<b style="border:none;"><i style="background-position:0 0;" onclick="removeMultiItem(this)"></i></b>';
                $(this).append(x);
                $(this).parents(".duoXuan").find(".diaCof").removeClass("diaCof");
                return false;
            });

            $(".fanYe a:eq(0)").hover(function(){
                $(this).siblings("a").css("border-left","1px solid #07ccfd");
            });
		})

		function removeMultiItem(obj) {
			var $container = $(obj).parents('div.duoOuter');
            $(obj).parents('dfn').removeClass('chosedfn');
            $(obj).parents('dfn').find('b').remove();
			if($container.find('dfn.chosedfn').length == 0) {
				$container.find('button.queRen').addClass('diaCof');
			}
		}

		function search() {
			var param = 'pageNo=' + pageNo + '&showSize=' + showSize + '&rowSize=' + rowSize
					+ '&startPubDate=' + $('#startPubDate').val() + '&endPubDate=' + $('#endPubDate').val()
					+ '&startDeadline=' + $('#startDeadline').val() + '&endDeadline=' + $('#endDeadline').val()
					+ '&hasAttach=' + $('#hasAttach').hasClass('chosed') + '&sort=' + ($('b.acTab[data-sort]').length > 0 ? $('b.acTab[data-sort]').attr('data-sort') : '');
			$.each($('#searchItem b[data-name]'), function() {
				param += '&' + $(this).attr('data-name') + '=' + $(this).attr('data-value');
			});
            $.ajax({
                url : '/searchXmh',
                type : 'post',
                dataType : 'json',
				data : param,
                beforeSend : function() {
                    layer.load(2, {shade: 0.1});
                },
                success : function(res) {
                    if(res && res.success) {
                        var html = laytpl($('#dataTemplate').html()).render({ data : res.attributes.data});
						$('#dataTbody').html(html); 
                        //显示分页
                        laypage({
                            cont: 'page',
                            pages: res.attributes.pages,
							first : 1,
							last : res.attributes.pages,
                            curr: pageNo, //当前页 
                            jump: function(obj, first) {
                                if(!first) {
                                    pageNo = obj.curr;
                                    search(pageNo);
                                }
                            }
                        });
						//处理头部分页
						$('#pageNo').html(pageNo);
						$('#pages').html('/&nbsp;' + res.attributes.pages);
						$('#pages').attr('data-pages', res.attributes.pages);
						$('#total').html('（' + res.attributes.total + '）');
						$(window).scrollTop(300);
                    }
                },
                complete : function() {
                    layer.closeAll('loading');
                }
            })
		}

        function initDate(startId, endId) {
            var start = {
                elem: '#' + startId,
                format: 'YYYY-MM-DD',
                choose: function(datas) {
                    end.min = datas; //开始日选好后，重置结束日的最小日期
                    end.start = datas //将结束日的初始值设定为开始日
                }
            };
            var end = {
                elem: '#' + endId,
                format: 'YYYY-MM-DD',
                choose: function(datas) {
                    start.max = datas; //结束日选好后，重置开始日的最大日期
                }
            };
            laydate(start);
            laydate(end);
        }

        /**
		 * 移除搜索项
		 * */
        function removeItem(obj) {
			var name = $(obj).parent().attr('data-name');
            $('.duoOuter div[data-name=' + name + ']').parents('.danXuan').find('.keXuan').height('20px');
			$('.duoOuter div[data-name=' + name + ']').parents('.danXuan').show();
            $(obj).parents('div:eq(0)').remove();
			if($("#searchItem .sxx").find('b[data-name]').length == 0) {
                $("#searchItem .sxx").html('');
			}
            pageNo = 1;
			search();
		}

		/**
		 * 清空筛选条件
		 * */
		function clearAll() {
            $("#searchItem .sxx").html('');
			$('.duoOuter').show();
			pageNo = 1;
			search();
		}

		/**
		 * 更多
		 * */
		function more(obj) {
			$(obj).parent().prev().height("auto");
            $(obj).replaceWith('<a class="shouQiLink" onclick="less(this)">收起<i class="zhanKai shouQi"></i></a>');
        }

		/**
		 * 收起
		 * */
		function less(obj) {
            $(obj).parent().prev().height("20px");
            $(obj).replaceWith('<a class="zhanKaiLink" onclick="more(this)">更多<i class="zhanKai"></i></a>');
        }

		/**
		 * 展开多选
		 * */
		function multi(obj) {
			var name = $(obj).parents('.duoOuter').find('div[data-name]').attr('data-name');
            $(obj).parents(".duoOuter").addClass("duoXuan");
            $(obj).parents(".duoOuter").removeClass("danXuan");
            var b = "<div style='text-align:center;margin-top: 10px;'><button type='button' class='confirmLink queRen diaCof' style='margin-right:20px;' onclick=\"confirmMulti(this)\">确认</button><button type='button' class='confirmLink' onclick='cancelMulti(this)'>取消</button></div>";
            $(obj).parents(".duoOuter").find(".keXuan").css("height","auto");
            $(obj).parents(".duoXuan").append(b);
            $(obj).parents(".duoOuter").find(".itermChose").hide();
		}

		/**
		 * 多选-确认
		 * */
		function confirmMulti(obj) {
			if($(obj).hasClass('diaCof')) {return;}
			var name = $(obj).parents('.duoOuter').find('div[data-name]').attr('data-name');
			var value = '';
			var text = '';
			$.each($('.duoOuter div[data-name=' + name + '] dfn.chosedfn'), function() {
				value += $(this).attr('data-value') + ',';
				text += $(this).text().trim() + '-';
			});
			if(value != '') {
				value = value.substring(0, value.length - 1);
                text = text.substring(0, text.length - 1);
			}
            addSearchItem(name, value, text);
            $(obj).parents(".duoOuter").hide();
            cancelMulti(obj);
			pageNo = 1;
			search();
		}

		/**
		 * 多选-取消
		 * */
		function cancelMulti(obj) {
            $(obj).parents(".duoOuter").find(".itermChose").show();
            $(obj).parents(".duoOuter").removeClass("duoXuan");
            $(obj).parents(".duoOuter").addClass("danXuan");
            $(obj).parents('.duoOuter').find('div[data-name]').css('height', '20px');
			$.each($(obj).parents('.duoOuter').find('div[data-name] dfn.chosedfn'), function() {
				$(this).removeClass('chosedfn');
				$(this).find('b').remove();
			});
            $(obj).parent("div").remove();
		}

		function addSearchItem(name, value, text) {
            //超过15个字省略
			if(text.length > 15) {
                text = text.substring(0, 15) + '...';
			}
            var searchItem = laytpl($('#searchItemTemplate').html()).render({name : name, value : value, text : text});
            var clearAll = '<b style="cursor: pointer;float: right;padding: 2px 8px;margin-top: -3px;" onclick="clearAll()">清空筛选条件</b>';
            $("#searchItem .sxx").append($("#searchItem .sxx b").length == 0 ? searchItem + clearAll : searchItem);
		}

		/**
		 * 勾选有图/附件
		 * */
        $(".spCent.itermTwo caption em i").click(function(){
            $(this).toggleClass("chosed");
			pageNo = 1;
			search();
        });

		function switchTab(obj, name) {
			var sort = $(obj).attr('data-sort');
			if(name) {
                if ($(obj).hasClass('acTab')) {
                    var sortType = $.trim(sort.replace(name, ''));
                    $(obj).attr('data-sort', name + (sortType == 'desc' ? ' asc' : ' desc'));
                    $(obj).find('i').toggleClass('dw');
                } else {
                    $(obj).attr('data-sort', name + ' desc');
                    $(obj).find('i').addClass('dw');
                }
            }
            $(obj).parent().find('b').removeClass('acTab');
            $(obj).addClass('acTab');
			pageNo = 1;
			search();
		}

		function toQuote(enquiryId) {
            layer.load(2, {shade: 0.1});
			$.ajax({
				url : '/canQuote',
				type : 'post',
				data : {enquiryId : enquiryId},
				dataType : 'json',
				success : function(data) {
					if(data && data.success) {
						[#if Session.currentRole?? && Session.currentRole.roleType == 1]
							//具有双重身份，但当前身份不是供应商，自动切换至供应商身份
							$.post('/user/switch', function(data) {
								if(data.success){
									location.href = '/enquiry/quote?enquiryId=' + enquiryId;
								}else{
									layer.alert('操作失败');
								}
							},"json");
						[#else]
							location.href = '/enquiry/quote?enquiryId=' + enquiryId;
						[/#if]
					} else {
						if(data.obj == 'login') {
							_showLoginWin();
						} else if(data.obj == 'companyInfo') {
							//没有公司
							layer.alert(data.msg, {title : '提示',btn : ['去绑定', '取消']},
								function() {
									window.open('/user/companySearch');
								}
							);
						} else if(data.obj == 'companyInfo.view') {
                            //待审核或审核未通过
                            layer.alert(data.msg, {title : '提示',btn : ['去查看', '取消']},
                                    function() {
                                        window.open('/company/info');
                                    }
                            );
                        } else {
							layer.alert(data.msg);
						}
					}
				},
				complete : function() {
					layer.closeAll('loading');
				}
			});
		}
	</script>
</body>
</html>